Socket
Socket
Sign inDemoInstall

merge

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    merge

(recursive)? merging of (cloned)? objects.


Version published
Maintainers
1
Install size
7.58 kB
Created

Package description

What is merge?

The merge npm package is a utility that allows you to merge multiple objects into one. It is useful when you want to combine configurations, settings, or other data structures in JavaScript. It performs a deep merge by default, meaning that it recursively merges properties of objects, but it can also be configured to perform a shallow merge.

What are merge's main functionalities?

Deep Merge

This feature allows for the deep merging of objects, meaning that nested objects will also be merged together. The code sample demonstrates merging two objects with nested properties.

{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge(object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }"}

Shallow Merge

This feature allows for the shallow merging of objects, which means that it will not recursively merge nested objects. The code sample demonstrates merging two objects without combining the nested properties.

{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge.recursive(false, object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { d: 3 }, e: 4 }"}

Other packages similar to merge

Readme

Source

Merge

(recursive)? merging of (cloned)? objects.

Install

Node.js

npm i merge
import merge from 'merge'

Browser

<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/dist/merge.browser.min.js"></script>
window.merge

API

merge(clone: boolean, ...items: Object[])
merge(...items: Object[])
merge.recursive(clone: boolean, ...items: Object[])
merge.recursive(...items: Object[])

Examples


// Merge 

{
	var objectA = {} 

	merge(objectA, 
		{ value: 1 }, 
		{ str: 'hello world' }
	)

	var objectB = merge(true, objectA, 
		{ value: 2 }
	)

	objectA // { value: 1, str: 'hello world' }
	objectB // { value: 2, str: 'hello world' }
}

// Recursive merge

{
	var objectA = {}

	merge.recursive(objectA, 
		{ level: { value: 1 } },
		{ level: { str: 'hello world' } }
	)
	var objectB = merge.recursive(true, objectA, 
		{ level: { value: 2 } }
	)

	objectA.level // { value: 1, str: 'hello world' }
	objectB.level // { value: 2, str: 'hello world' }
}

Test

Node.js

npm test

Browser

./dist/merge.browser.test.html

Keywords

FAQs

Last updated on 22 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc